import org.apache.spark.sql.SQLContext
import org.apache.spark.{SparkConf, SparkContext}

/**
  * @ Auther: o2o-rd-0008
  * @ Date:   2019/11/7 10:11
  * @ Param:  ${PARAM}
  * @ Description: 
  */
object d {

  def main(args: Array[String]): Unit = {
    val conf = new SparkConf()
    conf.setAppName(s"${this.getClass.getSimpleName}")
    conf.set("spark.debug.maxToStringFields", "500")
    conf.setMaster("local[*]")
    conf.set("es.nodes", "192.168.1.157")
    conf.set("es.port", "9200")
    conf.set("cluster.name", "O2OElastic")
    conf.set("spark.serializer", "org.apache.spark.serializer.KryoSerializer")
    conf.set("spark.sql.caseSensitive", "true")
    val sc = new SparkContext(conf)
    val sqlContext = new SQLContext(sc)
    sc.setLogLevel("WARN")
    sc.hadoopConfiguration.set("fs.s3a.access.key", "GAO7EO9FWKPJ8WFCQDME")
    sc.hadoopConfiguration.set("fs.s3a.secret.key", "LZ0xaHBSYKHaJ9ECDbX9f7zin79UZkXfGoNapRPL")
    sc.hadoopConfiguration.set("fs.s3a.endpoint", "https://obs.cn-north-1.myhuaweicloud.com")


    val days =30
    for (day <- 6 to 9) {
      println(day)

      val yushou_data = sqlContext.read.orc(s"s3a://dws-data/yiqing/day/zhibo2/2020/5/0${day}/")
      yushou_data.createOrReplaceTempView("zhibo_index")


      val country_1 = sqlContext.sql(
        s"""
           |select
           |region_type,
           |live,
           |viewer,
           |liveGood,
           |anchor
           |from zhibo_index
           |where region_type=0
         """.stripMargin
      )
      country_1.repartition(1).write.csv(s"D:\\xuechunhua\\country\\5月\\${day}")



    /*  val province_1 = sqlContext.sql(
        s"""
           |select
           |province,
           |sum(live) as province_liveCount ,
           |sum(viewer) as province_viewerCount,
           |sum(liveGood) as province_liveGoodCount,
           |sum(anchor) as province_anchorCount
           |from zhibo_index
           |where region_type=1
           |group by province
         """.stripMargin
      )



      province_1.repartition(1).write.csv(s"D:\\xuechunhua\\province\\5月\\${day}")*/


    }


    sc.stop()


  }

}
